﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.DBM;

namespace KPIS.GERP.GHRMS.BLL
{
    public class HisTrainingBLL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public DataSet ListTrainingHistories(Nullable<int> EmpSeq, Nullable<int> Sequence)
        {
            dbManager.CreateParameters(3);
            dbManager.AddParameters(0, "@RecordStatus", SystemInfo._DeleteRecordStatus);
            dbManager.AddParameters(1, "@EmpSeq", EmpSeq);
            dbManager.AddParameters(2, "@Sequence", Sequence);

            string strSQL;
            strSQL = "SELECT ct.*"
                + ", c.TRAINING_COURSE_DESCR, c.DATE_TRAINING_START, c.DATE_TRAINING_END"
                + ", ins.TRAINING_INS_DESCR"
                + " FROM HRM_TRAINING_COURSES_TRAINEES ct"
                    + " INNER JOIN HRM_PS_EMPLOYEES e ON ct.EMP_SEQ = e.EMP_SEQ"
                    + " INNER JOIN HRM_TRAINING_COURSES c ON ct.TRAIN_SEQ = c.TRAIN_SEQ"
                    + " LEFT JOIN HRM_TRAINING_INSTITUTES ins ON c.TRAINING_INS_SEQ = ins.TRAINING_INS_SEQ"
                + " WHERE ct.RECORD_STATUS not like @RecordStatus"
                + " AND c.CLOSED = 1"
                + (EmpSeq.HasValue ? " AND ct.EMP_SEQ = @EmpSeq" : "")
                + (Sequence.HasValue ? " AND ct.TRAN_SEQ = @Sequence" : "");

            DataSet ds = new DataSet();
            dbManager.Open();
            ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
            dbManager.Dispose();
            return ds;
        }
    }
}
